package com.corp.common.base.mq.message;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;

/**
 * @Author Keanu
 * @Date 2020/7/16 0016 16:49
 * @Version
 **/
public class BornTimeMessage implements Serializable {

    private static final long serialVersionUID = -8824396936559100700L;

    private Instant bornTimestamp = Instant.now();

    @JsonIgnore
    public Duration betweenNow(){
        if(bornTimestamp != null){
            Instant now = Instant.now();
            return Duration.between(bornTimestamp, now);
        }else{
            return Duration.of(0L, ChronoUnit.SECONDS);
        }
    }
}
